/*
 * @Author: your name
 * @Date: 2020-05-06 11:12:29
 * @LastEditTime: 2020-10-30 14:19:34
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /yigo/src/Actions/UserActions.js
 */
import {
    CALL_API
} from '../../Api'


/**
 * @description: 公共的action
 * @param {type} 
 * @return: 
 */
export const commonAction = (url,parameter,method,isFile, exit, type) => {
  // arguments  可以获取多余的参数
    return {
        [CALL_API]:{
          address:url,
          body:parameter || '',
          method: method || 'POST',
          isFile,
          type: type || url,
          exit: exit || ''
        }
      }
}

//--------------------------   账户操作   --------------------------------

/**
 * @description: 用户登录操作
 * @param {type} 
 * @return: 
 */
export const onLogin = (parameter) => (dispatch) => dispatch(commonAction('api/onLogin',parameter,null,false))

/**
 * @description: 商家注册
 * @param {type} 
 * @return: 
 */
export const registerBusiness = (parameter) => (dispatch) => dispatch(commonAction('api/registerBusiness',parameter,null,false))
/**
 * @description: 录入商品
 * @param {type} 
 * @return: 
 */
export const commitFood = (parameter) => (dispatch) => dispatch(commonAction('api/commitfood',parameter,null,false, 'other'))
/**
 * @description: 商品列表
 * @param {type} 
 * @return: 
 */
export const foodList = (parameter) => (dispatch) => dispatch(commonAction('api/foodList',parameter,null,false))

/**
 * @description: 单个商品详情信息
 * @param {type} 
 * @return: 
 */
export const singleGoodDetail = (parameter) => (dispatch) => dispatch(commonAction('api/singleGoodDetail',parameter,null,false))

/**
 * @description: 批量上传文件
 * @param {type} 
 * @return: 
 */
export const uploadFile = (parameter) => (dispatch) => dispatch(commonAction('api/uploads',parameter,null,true))
